package com.example.bob.uicontrols;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;

/**
 * Created by Bob on 2016/3/12.
 */
public class AtyUsingCheckBox extends Activity {

    private CheckBox checkBox1, checkBox2, checkBox3, checkBox4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_using_checkbox);
        checkBox1 = (CheckBox) findViewById(R.id.checkbox1);
        checkBox2 = (CheckBox) findViewById(R.id.checkbox2);
        checkBox3 = (CheckBox) findViewById(R.id.checkbox3);
        checkBox4 = (CheckBox) findViewById(R.id.checkbox4);

        findViewById(R.id.btnSubmit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String str = "中午要吃的东西有：\n";
                if(checkBox1.isChecked()){
                    str+=checkBox1.getText()+"\n";
                }
                if(checkBox2.isChecked()){
                    str+=checkBox2.getText()+"\n";
                }
                if(checkBox3.isChecked()){
                    str+=checkBox3.getText()+"\n";
                }
                if(checkBox4.isChecked()){
                    str+=checkBox4.getText()+"\n";
                }
                new AlertDialog.Builder(AtyUsingCheckBox.this).setTitle("结果").setMessage(str).setPositiveButton("关闭",null).show();
            }
        });
    }
}
